package log;

import org.aspectj.lang.annotation.*;

/**
 * @Author: fancyears·milos·malvis
 * @Description:
 * @Date: Created in  2019/4/28 15:01
 * @Modified By:
 */
@Aspect
public class LoggerWithoutXml {

    /** Following is the definition for a pointcut to select
     *  all the methods available. So advice will be called
     *  for all the methods.
     *
     *  这个定义的切入点
     */
    @Pointcut("execution(* bean.Parent.*(..))")
    private void pointCutDefine(){
        System.out.println("执行selectAll");
    }
    /**
     * This is the method which I would like to execute
     * before a selected method execution.
     */
    @Before("pointCutDefine()")
    public void beforeAdvice(){
        System.out.println("切点前操作");
    }
    /**
     * This is the method which I would like to execute
     * after a selected method execution.
     */
    @After("pointCutDefine()")
    public void afterAdvice(){
        System.out.println("切点后操作");
    }
    /**
     * This is the method which I would like to execute
     * when any method returns.
     */
    @AfterReturning(pointcut = "pointCutDefine()", returning="retVal")
    public void afterReturningAdvice(Object retVal){
        System.out.println("返回值:" + retVal.toString() );
    }
    /**
     * This is the method which I would like to execute
     * if there is an exception raised by any method.
     */
    @AfterThrowing(pointcut = "pointCutDefine()", throwing = "ex")
    public void AfterThrowingAdvice(IllegalArgumentException ex){
        System.out.println("发生异常: " + ex.toString());
    }
}
